package com.so.web.controller.monitor;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.so.common.annotation.Log;
import com.so.common.core.controller.BaseController;
import com.so.common.core.domain.R;
import com.so.common.enums.BusinessType;
import com.so.common.utils.poi.ExcelUtil;
import com.so.system.domain.SysOperLog;
import com.so.system.service.ISysOperLogService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 操作日志记录
 *
 * @author system
 */
@RestController
@RequestMapping("/monitor/operlog")
public class SysOperlogController extends BaseController {

    @Resource
    private ISysOperLogService operLogService;

    @PreAuthorize("@ss.hasPermi('monitor:operlog:list')")
    @GetMapping("/list")
    public R<Page<SysOperLog>> list(Page<SysOperLog> page, SysOperLog operLog) {
        Page<SysOperLog> result = operLogService.selectOperLogList(page,operLog);
        return R.ok(result);
    }

    @Log(title = "操作日志", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperLog operLog) {
        List<SysOperLog> list = operLogService.selectOperLogList(operLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<>(SysOperLog.class);
        util.exportExcel(response, list, "操作日志");
    }

    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/{operIds}")
    public R<Void> remove(@PathVariable Long[] operIds) {
        operLogService.removeBatchByIds(Arrays.asList(operIds));
        return R.ok();
    }

    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @PreAuthorize("@ss.hasPermi('monitor:operlog:remove')")
    @DeleteMapping("/clean")
    public R<Void> clean() {
        operLogService.cleanOperLog();
        return R.ok();
    }
}
